package labox.innovation.gameserver.model.actor.stat;

import labox.innovation.gameserver.datatables.Experience;
import labox.innovation.gameserver.model.L2PetDataTable;
import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.actor.instance.L2PetInstance;
import labox.innovation.gameserver.network.SystemMessageId;
//import labox.innovation.gameserver.network.serverpackets.SocialAction;
import labox.innovation.gameserver.network.serverpackets.StatusUpdate;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;
import labox.innovation.gameserver.skills.Stats;

public class PetStat extends SummonStat {
	// =========================================================
	// Data Field

	// =========================================================
	// Constructor
	public PetStat(L2PetInstance activeChar) {
		super(activeChar);
	}

	// =========================================================
	// Method - Public
	public boolean addExp(int value) {
		if (!super.addExp(value))
			return false;

		/* Micht : Use of PetInfo for C5
		 StatusUpdate su = new StatusUpdate(getActiveChar().getObjectId());
		 su.addAttribute(StatusUpdate.EXP, getExp());
		 getActiveChar().broadcastPacket(su);
		 */
		getActiveChar().updateAndBroadcastStatus(1);
		// The PetInfo packet wipes the PartySpelled (list of active  spells' icons).  Re-add them
		getActiveChar().updateEffectIcons(true);

		return true;
	}

//	@Override
	public final boolean addLevel(int value) {
		if (getLevel() + value > (Experience.MAX_LEVEL - 1))
			return false;

//		boolean levelIncreased = super.addLevel(value);
//
//		// Sync up exp with current level
//		if (getExp() > getExpForLevel(getLevel() + 1) || getExp() < getExpForLevel(getLevel()))
//			setExp(Experience.LEVEL[getLevel()]);
//
//		if (levelIncreased)
//			getActiveChar().getOwner().sendMessage("Your pet has increased it's level.");
//
//		StatusUpdate su = new StatusUpdate(getActiveChar().getObjectId());
//		su.addAttribute(StatusUpdate.LEVEL, getLevel());
//		su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
//		su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
//		getActiveChar().broadcastPacket(su);
//		getActiveChar().broadcastPacket(new SocialAction(getActiveChar().getObjectId(), SocialAction.LEVEL_UP));
//		// Send a Server->Client packet PetInfo to the L2PcInstance
//		getActiveChar().updateAndBroadcastStatus(1);
//
//		if (getActiveChar().getControlItem() != null)
//			getActiveChar().getControlItem().setEnchantLevel(getLevel());
//
//		return levelIncreased;
		return false;
	}

//	@Override
	public final int getExpForLevel(int level) {
		try {
//			return L2PetDataTable.getInstance().getPetData(getActiveChar().getNpcId(), level).getPetMaxExp();
		} catch (NullPointerException e) {
			_log.warn("Pet NPC ID " + getActiveChar().getNpcId() + ", level " + level + " is missing data from pets_stats table!");
			return 5000000 * level; // temp value calculated from lvl 81 wyvern, 395734658
		}
		return -1;
	}

	// =========================================================
	// Method - Private

	// =========================================================
	// Property - Public
	@Override
	public L2PetInstance getActiveChar() {
		return (L2PetInstance) super.getActiveChar();
	}

	public final int getFeedBattle() {
		return getActiveChar().getPetData().getPetFeedBattle();
	}

	public final int getFeedNormal() {
		return getActiveChar().getPetData().getPetFeedNormal();
	}

	@Override
	public void setLevel(int value) {
		getActiveChar().stopFeed();
		super.setLevel(value);

		getActiveChar().setPetData(L2PetDataTable.getInstance().getPetData(getActiveChar().getTemplate()._id, getLevel()));
		getActiveChar().startFeed();

		if (getActiveChar().getControlItem() != null)
			getActiveChar().getControlItem().setEnchantLevel(getLevel());
	}

	public final int getMaxFeed() {
		return getActiveChar().getPetData().getPetMaxFeed();
	}

	@Override
	public int getMaxHp() {
		return (int) calcStat(Stats.MAX_HP, getActiveChar().getPetData().getPetMaxHP(), null, null);
	}

	@Override
	public int getMaxMp() {
		return (int) calcStat(Stats.MAX_MP, getActiveChar().getPetData().getPetMaxMP(), null, null);
	}
}
